#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket

def Socket(sock, addr):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('www.dearmrli.com',80))
    
    # 发送数据:
    s.send('GET / HTTP/1.1\r\nHost: www.sina.com.cn\r\nConnection: close\r\n\r\n')
    
    #接受数据
    buffer = []
    while True:
        #
        d = s.recv(1024)
        if d:
            buffer.append(d)
        else:
            break
    
    data = ''.join(buffer)
    
    # 关闭链接
    s.close();
    
    header, html = data.split('\r\n\r\n',1)
    print header
    with open('html.html','wb') as f:
        f.write(html)
        
    with open('header.html','wb') as f:
        f.write(header)
        
    with open('all.html','wb') as f:
        f.write(data)
